﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Tunnel.Devices.DeviceEntity
{
    public partial class TSForm : Form
    {
        TS ts = new TS();

        public TSForm(TS ts)
        {
            InitializeComponent();
            this.ts = ts;
            try
            {
                if (!Global.PlcStatus[ts.Protocol])
                {
                    ok.Enabled = false;
                    ok.Text = "故障";
                }
            }
            catch { }

            if (ts.StatusDescription == "红灯")
            {
                rbRed.Checked = true;
            }
            if (ts.StatusDescription == "黄灯")
            {
                rbYellow.Checked = true;
            }
            if (ts.StatusDescription == "绿灯")
            {
                rbGreen.Checked = true;
            }
            if (ts.StatusDescription == "左转")
            {
                rbTurn.Checked = true;
            }
            this.lbName.Text = ts.Name;
            label1.Text = $"{ts.RedId}  {ts.GreenId}";

        }

        private void ok_Click(object sender, EventArgs e)
        {
            if(rbRed.Checked==true)
            {
                ts.SendCommand(CommandType.交通信号灯红);
            }
            if (rbYellow.Checked == true)
            {
                ts.SendCommand(CommandType.交通信号灯黄);
            }
            if (rbGreen.Checked == true)
            {
                ts.SendCommand(CommandType.交通信号灯绿);
            }
            if (rbTurn.Checked == true)
            {
                ts.SendCommand(CommandType.交通信号灯左);
            }
            this.Close();
        }

        private void exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
